<?php
$loader->requireOnce('includes/TreatmentDuration.class.php');

class C_OdonService extends Controller {
    private $logger;

    function C_OdonService($template_mod = "general") {
        parent::Controller();
        $this->logger = LoggerManager::getLogger('module.dept_odontology.controllers.C_OdonService');
        $this->template_mod = $template_mod;
        $this->view->path="odon_service";
    }
    
    function actionCheckOpenTreatmentDurationAjax() {
    	$patientId = $_GET['patientId'];
    	$departmentId = $this->_me->get_department_id();
    	    	
    	$ticketId = Celini::newORDO('Ticket')->isAnyOpenTicketByDepartment($patientId, $departmentId);
    	if ($ticketId === false) {
    	    return -1;
    	}
    	
    	$treatmentInstanceId = Celini::newORDO('RhmTreatmentInstance')->isTreatmentInstanceAvailableForToday($ticketId);
    	if ($treatmentInstanceId === false) {
    	    return -1;
    	}
    	return $treatmentInstanceId;
    }
    
    function actionGetServiceCodeAutocompleteAjax() {
        $q = $_GET['q'];
        if (!$q) return;
        $q = strtoupper($q);
        $result = Celini::newORDO('Service')->getServiceAutoCompleteByCode($q, $_GET['serviceType']);
        foreach ($result as $item) {
            $price = L10nHelper::renderNumber($item['price'], 0);
             echo $item['code'] . '|' . $item['name'] . '|' . $item['service_id'] . '|' . $price . '|' . $item['price'] . "\n";
        }
    }
}
?>